package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.hydrology.dto.CgkyjDto;
import org.jeecg.modules.demo.hydrology.dto.CscddyDto;
import org.jeecg.modules.demo.hydrology.entity.Cgkyj;
import org.jeecg.modules.demo.hydrology.entity.Cscddy;
import org.jeecg.modules.demo.hydrology.mapper.CscddyMapper;
import org.jeecg.modules.demo.hydrology.service.ICscddyService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 抽放水基础信息
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Service
public class CscddyServiceImpl extends ServiceImpl<CscddyMapper, Cscddy> implements ICscddyService {
    @Autowired
    private CscddyMapper cscddyMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    /**
     * 抽放水基础信息-分页列表查询
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<CscddyDto> getList(Page<Cscddy> page, QueryWrapper<Cscddy> queryWrapper) {
        Page<Cscddy> cscddyPage = cscddyMapper.selectPage(page, queryWrapper);
        List<CscddyDto> collect = cscddyPage.getRecords().stream().map(cscddy -> {
            CscddyDto cscddyDto = new CscddyDto();
            BeanUtils.copyProperties(cscddy, cscddyDto);
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", cscddy.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            if (sysDepart != null){
                cscddyDto.setStationName(sysDepart.getDepartName());
            }
            return cscddyDto;
        }).collect(Collectors.toList());
        IPage<CscddyDto> cscddyDtoIPage = new Page<>();
        cscddyDtoIPage.setRecords(collect);
        cscddyDtoIPage.setTotal(cscddyPage.getTotal());
        cscddyDtoIPage.setPages(page.getPages());
        cscddyDtoIPage.setSize(page.getSize());
        return cscddyDtoIPage;
    }
}
